package com.example.fq.s3;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.List;

/**
 * Created by fq on 15-5-11.
 */
public class CarAdapter extends ArrayAdapter<Car> {
    private int resourceId;

    public CarAdapter(Context context, int textViewResourceId, List<Car> objects) {
        super(context, textViewResourceId, objects);
        resourceId = textViewResourceId;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Car car = getItem(position);
        View view;
        if (convertView == null) {
            view = LayoutInflater.from(getContext()).inflate(resourceId, null);
        }else {
            view = convertView;
        }
        TextView carStyleText = (TextView) view.findViewById(R.id.car_style);
        TextView carPriceText = (TextView) view.findViewById(R.id.car_price);
        carStyleText.setText(car.getStyle());
        carPriceText.setText(car.getPrice());
        return view;
    }
}
